package org.net.cms.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.net.cms.controller.app.application.vo.AppApplicationReqVO;
import org.net.cms.dao.ApplicationDto;

import java.util.List;

@Mapper
public interface ApplicationMapper {

    @Insert("INSERT INTO application (parent_card_id, parent_phone, student_card_id, name, sex, birthday, domicile, status) " +
            "VALUES (#{parentCardId}, #{parentPhone}, #{studentCardId}, #{name}, #{sex}, #{birthday}, #{domicile}, #{status})")
    int addAdmissionApplication(AppApplicationReqVO studentReqVO);

    @Select("select status from application where student_card_id = #{studentCardId} and deleted = 0")
    int studentApplicationStatus(String studentCardId);

    @Update("UPDATE application " +
            "SET status = #{status}, update_time = NOW() " +
            "WHERE id = #{id} AND deleted = 0")
    int updateStatus(int id, int status);

    @Update("update application set deleted = 1 where id = #{id} and deleted = 0")
    int deleteAdmission(int id);

    @Select("select * from application where id = #{id} and deleted = 0")
    ApplicationDto getApplicationById(int id);

    @Select("select * from application where status = #{type} and deleted = 0")
    List<ApplicationDto> applicationList(int type);

    @Select("select * from application where parent_phone = #{phone} and deleted = 0")
    List<ApplicationDto> getMyApplicationListByPhone(String phone);

    // 查看是否存在状态为解绑待审核，状态为4的信息
    @Select("select * from application where student_card_id = #{studentCardId} and status = 4")
    ApplicationDto selectUnbindApplication(String phone, String studentCardId);
}
